//设计按钮触发后

package UserInterface;

import javax.swing.*;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.*;

class UserInterface3 {
    public static void main(String[] args) {

        JPanel panel1 = new JPanel();
        JPanel panel2 = new JPanel(); // 创建面板
        JButton button1 = new JButton("B1");
        JButton button2 = new JButton("B2");
        JButton button3 = new JButton("B3");
        JButton button4 = new JButton("B4"); // 创建按钮

        ImageIcon icon = new ImageIcon("win.jpg"); // 添加图片
        JFrame win = new JFrame("win1");
        JButton jbtn = new JButton("打开新窗口", icon);
        win.setSize(200, 200);
        win.setVisible(true);
        win.setTitle("按键功能显示");
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setLayout(new FlowLayout()); // 窗口设置

        win.add(panel1);
        win.add(panel2);

        panel1.add(button1);
        panel1.add(button2);
        panel2.add(button3);
        panel2.add(button4);
        panel1.setBackground(Color.red);
        panel2.setBackground(Color.cyan); // 设置颜色
        win.validate();
        button1.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        JFrame newf = new JFrame("新建窗体");
                        newf.setSize(150, 150);
                        newf.setVisible(true); // 设置按钮触发后
                    }
                });
    }
}
